﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data.SqlClient;
using TJADRICD.Model;
using TJADRICD.DLL;

namespace TJADRICD.CollaborativeDesignPlugin
{
    public class UserRoleDao
    {
        public UserRole getRoleInfoByMajorID(string majorId)
        {

            string selectStr = "select * from userRole where Mayor_ID = '" + majorId+"'";
            UserRole userRole = null;
            try
            {
                SqlConnection conn = Connection.getSqlConnection(CONST.connstr);
                SqlCommand cmd = new SqlCommand(selectStr, conn);
                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    userRole = new UserRole();
                    userRole.ProjectId = reader[0].ToString();
                    userRole.Role = reader[1].ToString();
                    userRole.UserId = reader[2].ToString();
                    userRole.SubProjectId = reader[4].ToString();
                    userRole.MayorId = reader[3].ToString();
                }
                conn.Close();
                reader.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("获取数据库信息时候发生了错误：" + e.Message);
                return userRole;
            }
            return userRole;
        }

        public List<String> getRoleInfoByProId(string proId , string subProId)
        {
             
            string selectStr = "select * from userRole where Project_ID = '" + proId + "' and Sub_Project_ID = '" + subProId +"'";
            List<String> userRoleList = new List<String>();
            try
            {
                SqlConnection conn = Connection.getSqlConnection(CONST.connstr);
                SqlCommand cmd = new SqlCommand(selectStr, conn);
                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    userRoleList.Add(reader[2].ToString());
                }
                conn.Close();
                reader.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("获取数据库信息时候发生了错误：" + e.Message);
                return userRoleList;
            }
            return userRoleList;
        }
    }
}
